package com.jokins.admin.vue.gitlog.action;

import com.jokins.admin.vue.gitlog.actioncontext.SaveApplyDoc;
import com.jokins.admin.vue.gitlog.mapper.ApplyMapper;
import com.jokins.admin.vue.gitlog.param.SaveApplyParam;
import com.jokins.common.actions.action.BaseAction;
import com.jokins.common.actions.exception.BusinessException;
import com.jokins.common.entry.vue.gitlog.Apply;
import com.jokins.common.util.BusinessCode;
import com.jokins.common.util.SqlTypeConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SaveApplyDocAction extends BaseAction<SaveApplyDoc> {

    @Autowired
    private ApplyMapper applyMapper;

    @Override
    protected void process(SaveApplyDoc actionContext) throws BusinessException {
        SaveApplyParam param = actionContext.getParam();
        try {
            Apply apply = new Apply();
            SqlTypeConverter.copyEntity(param, apply);
            applyMapper.insert(apply);
        } catch (Exception e) {
            log.error("保存失败", e);
            throw new BusinessException("保存失败", BusinessCode.PARAM_ERROR);
        }
    }
}
